package top.healthylife.gateway.platform.softwind.api.api.enterpriseinvoice;

import cn.hutool.core.bean.BeanUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import top.healthylife.basics.utils.exception.BusinessException;
import top.healthylife.basics.utils.utils.SystemThreadLocal;
import top.healthylife.gateway.core.service.ParentFace;
import top.healthylife.gateway.dto.annotation.ApiServiceExplain;
import top.healthylife.gateway.dto.request.req.ApiReqDto;
import top.healthylife.gateway.feignapi.utils.ApiInvokeHelper;
import top.healthylife.gateway.platform.softwind.api.util.WindHttpUtil;
import top.healthylife.gateway.platform.softwind.dto.enterpriseinvoice.req.WindReqInvoiceConsolidationListDto;
import top.healthylife.gateway.platform.softwind.dto.enterpriseinvoice.res.WindResInvoiceConsolidationListDto;
import top.heathylife.gateway.common.cons.SystemCons;

import java.util.Map;

/**
 * @author : GaoZeXi
 * @date 2021/11/29 14:46
 */
@Slf4j
@Service
@ApiServiceExplain(docUrl = "https://wfq2020.com/channel-admin/#/login", price = 20, apiName = "发票合并接口", info = "发票合并接口")
public class WindInvoiceConsolidationApi implements ParentFace<WindReqInvoiceConsolidationListDto, WindResInvoiceConsolidationListDto> {
    static final String URL = "/wuneng-web-api/v2/api/invoice/getInvoiceMergeList";

    @Override
    public WindResInvoiceConsolidationListDto execute(WindReqInvoiceConsolidationListDto t) throws Exception {
        return WindHttpUtil.httpRequest(t, URL, WindResInvoiceConsolidationListDto.class);
    }

    public WindResInvoiceConsolidationListDto executeByApiGateway(ApiReqDto reqDto) throws Exception {

        //1.通过数据网关调用接口
        Map<String, Object> map = BeanUtil.beanToMap(reqDto);
        String secret = SystemThreadLocal.get(SystemCons.secret);


        //首次调用获取总数,计算分页
        WindResInvoiceConsolidationListDto windResInvoiceConsolidationListDto;
        try {
            windResInvoiceConsolidationListDto = ApiInvokeHelper.results(
                    SystemCons.TYC_SHORT_NAME,
                    this.getClass().getAnnotation(ApiServiceExplain.class).apiName(),
                    reqDto,
                    secret);
        } catch (Exception e) {
            throw new BusinessException("[发票合并接口]调用异常,异常信息:", e.getMessage());
        }
        return windResInvoiceConsolidationListDto;
    }
}
